package com.itguigu.rabbitmq.seven;

import com.itguigu.rabbitmq.utils.RabbitMqutil;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

/**
 * @Date 2021/7/19 9:28
 * @Created by wangle
 * @Description
 */
public class EMITlogtopic {

    public static final String exchangeName = "topic_logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqutil.getChannel();
        //声明交换机
        channel.exchangeDeclare(exchangeName, "topic");
        Map<String, String> bindmap = new HashMap<>();

        bindmap.put("quick.orange.rabbit", "被队列 Q1Q2 接收到");
        bindmap.put("lazy.orange.elephant", "被队列 Q1Q2 接收到");
        bindmap.put("quick.orange.fox", "被队列 Q1 接收到");
        bindmap.put("azy.brown.fox", "被队列 Q2 接收到");
        bindmap.put("lazy.pink.rabbit", "虽然满足两个绑定但只被队列 Q2 接收一次");
        bindmap.put("quick.brown.fox", "不匹配任何绑定不会被任何队列接收到会被丢弃");
        bindmap.put("quick.orange.male.rabbit", "是四个单词不匹配任何绑定会被丢弃");
        bindmap.put("lazy.orange.male.rabbit", "是四个单词但匹配 Q2");


        for (Map.Entry<String, String> bindentry : bindmap.entrySet()
        ) {

            String routingkey = bindentry.getKey();
            String message = bindentry.getValue();
            channel.basicPublish(exchangeName, routingkey, null, message.getBytes(StandardCharsets.UTF_8));
            System.out.println("发出消息:" + message);

        }

    }
}
